package com.example.huang.controller;

import com.example.huang.entity.User;
import com.example.huang.mapper.LoginMapper;
import com.example.huang.service.LoginService;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.function.Supplier;
import java.util.logging.Logger;

@MapperScan(basePackages="com.example.demo.mapper")
@RestController
public class LoginController {
    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private LoginService loginService;
    // HelloWorld.class 就是你要打印的指定类的日志，
    // 如果你想在其它类中打印，那就把 HelloWorld.class 替换成目标类名.class 即可。
    //  Logger logger = (Logger) LoggerFactory.getLogger(LoginController.class);
    //logger.info("Hello World");
    @ResponseBody
    @RequestMapping(value = "/login" , consumes = "application/json")
    public Object Login3(@RequestBody User user) {

        //logger.info((Supplier<String>) user);
        System.out.println(user);
        return loginService.login(user);
    }
}
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//
//import javax.annotation.Resource;
//@Slf4j
//@Controller
//public class LoginController {
//
//    //将Service注入Web层
//    @Resource
//    UserService userService;
//
//    //实现登录
//    @RequestMapping("/login")
//    public String show(){
//        return "login";
//    }
//
//    @RequestMapping(value = "/loginIn",method = RequestMethod.POST)
//    public String login(String name,String password){
//        UserBean userBean = userService.LoginIn(name, password);
//        log.info("name:{}",name);
//        log.info("password:{}",password);
//        if(userBean!=null){
//            return "success";
//        }else {
//            return "error";
//        }
//    }
//    @RequestMapping("/signup")
//    public String disp(){
//        return "signup";
//    }
//
//    //实现注册功能
//    @RequestMapping(value = "/register",method = RequestMethod.POST)
//    public String signUp(String name,String password){
//        userService.Insert(name, password);
//        return "success";
//    }
//}
